﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using VINETLIFE.BL;
using VINETLIFE.DO;
using System.IO;

namespace VINETLIFE.AdminCP
{
    public partial class PaymentMethod : System.Web.UI.Page
    {
        cmsPaymentMethodDO objPay = new cmsPaymentMethodDO();
        protected void Page_Load(object sender, EventArgs e)
        {
            //bindToDropDown(cboCategoryCate);
            //Functions.ddlDatabinder(cboTrangThai, cmsSytemStatusDO.CREATEDBYID_FIELD, cmsSytemStatusDO.TITLE_FIELD, new cmsCategoryBL().SelectAdmin(false));
            if (Request.QueryString["PaymentMethodId"] != null)
            {
                objPay.PaymentMethodId = int.Parse(Request.QueryString["PaymentMethodId"].ToString());

                if (!IsPostBack)
                {
                    initForm();
                }
            }
        }
       
        private void initForm()
        {
          
            objPay = new cmsPaymentMethodBL().Select(objPay);
            txtPhuongThucTT.Text = objPay.PaymentCode;
            txtMoTa.Content = objPay.Note;
            txtNgayTao.Text = objPay.CreatedDate.ToString("dd/MM/yyy");
            txtOrderID.Text = objPay.OrderSequence.ToString();
            if (objPay.LastSaveDate != objPay.CreatedDate)
            {
                NgaySua.Visible = true;
                txtNgaySua.Text = objPay.LastSaveDate.ToString("dd/MM/yyy");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            initObject();
            if (objPay.PaymentMethodId <= 0)
            {
                objPay.CreatedDate = DateTime.Now;
                objPay.LastSaveDate = DateTime.Now;
                new cmsPaymentMethodBL().Insert(objPay);
            }
            else
            {
                objPay.LastSaveDate = DateTime.Now;
                new cmsPaymentMethodBL().Update(objPay);
            }
            Functions.Alert("Cập nhật thành công!", "ListPaymentMethod.aspx");
        }
        private void initObject()
        {
            objPay = new cmsPaymentMethodBL().Select(objPay);
            objPay.PaymentCode = txtPhuongThucTT.Text;
            objPay.Note = txtMoTa.Text;
            objPay.CreatedById = int.Parse(Session["UserID"].ToString());
            objPay.OrderSequence = int.Parse(txtOrderID.Text.ToString());
        }

        protected void btnHuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("/AdminCP/ListPaymentMethod.aspx");
        }
    }
}